<template>
	<view class="withdraw">
		<view class="top">
			<view class="status_bar"></view>
			<view class="nav">
			<!-- 	<uni-icons type="arrowleft" size="25" color='#fff'></uni-icons> -->
				<image src="../../../static/img/back.png" mode=""  @click="back"></image> 申请提现
			</view>
			<view class="flex">
				<view class="money">
					<view class="number">{{initData.withdrawAmount}}</view>
					<view class="text">提现额度(元)</view>
				</view>
				<view class="money">
					<view class="number">{{initData.withdrawAbleAmount}}</view>
					<view class="text">可提现额度(元)</view>
				</view>
			</view>

		</view>
		<view class="msg">
			<view class="row">
				<text class="must">*</text>
				<text class="text">开户银行:</text>
				<input type="text" value="bank" v-model="bankCode" />
				<!-- <picker @change="bindPickerChange" :value="index" :range="array">
					<view class="uni-input">{{ array[index] }}
						<uni-icons type="arrowdown" size="20" color='#ddd'></uni-icons>
					</view>
				</picker> -->
			</view>
			<view class="row">
				<text class="must">*</text>
				<text class="text">支行名称:</text>
				<input type="text" value="bankBranch" v-model="bankBranch" />
			</view>
			<view class="row">
				<text class="must">*</text>
				<text class="text">银行卡号:</text>
				<input type="text" value="bankCard" v-model="bankCard" />
			</view>
			<view class="row">
				<text class="must">*</text>
				<text class="text">姓 名:</text>
				<input type="text" value="agentName" v-model="agentName" />
			</view>
			<view class="row">
				<text class="must">*</text>
				<text class="text">提现金额:</text>
				<text class="disabled">{{initData.withdrawAbleAmount}}</text>
			</view>
			<view class="row" v-if="initData.whether.value==0">
				<text class="must">*</text>
				<text class="text">设置提现密码:</text>
				<input type="number" value="" maxlength="6" password='true' v-model="password" />
			</view>
			<view class="row" v-if="initData.whether.value==0">
				<text class="must">*</text>
				<text class="text">重复确认密码:</text>
				<input type="number" value="" maxlength="6" password='true' v-model="twopwd" />
			</view>
			<view class="row" v-if="initData.whether.value==1">
				<text class="must">*</text>
				<text class="text">提现密码:</text>
				<input type="number" value="" maxlength="6" password='true' v-model="tixianpwd" />
			</view>
		</view>
		<view class="button" @click="go_withdraw()">申请提现</view>
	</view>
</template>

<script>
	import {
		uniIcons
	} from '@dcloudio/uni-ui';
	import withdraw from '../../../servers/agent/withdraw/withdraw.js';
	export default {
		components: {
			uniIcons
		},
		data() {
			return {
				index: 0,
				array: [],
				initData: '',
				twopwd: '',
				password: '',
				tixianpwd: '',
				bankBranch: '',
				bankCard: '',
				bankCode: '',
				agentName: '',
				date: '',
				whether: ''
				
			};
		},
		mounted() {
			var day2 = new Date();
			day2.setTime(day2.getTime());
			this.date = day2.getFullYear() + "-" + (day2.getMonth() + 1) + "-" + day2.getDate()
			uni.showLoading({
				title: '数据加载中',
				mask: true
			});
			withdraw.initData(this.date)
				.then(res => {
					this.initData = res.data;
					this.bankBranch = res.data.bankBranch;
					this.bankCard = res.data.bankCard;
					this.agentName = res.data.agentName;
					this.bankCode=res.data.bankCode;
					if (res.data.whether.value == 1) {
						this.whether = 0
					} else {
						this.whether = 1
					}
					// this.index = this.array.indexOf(this.initData.bankCode)
					// this.bankCode = this.array[this.index]
					uni.hideLoading();
				})
				.catch(err => {
					console.log(new Error('请检查网络后重试'));
				});
				withdraw.bankHistory()
					.then(res => {
						this.array=res.data;						
						uni.hideLoading();
					})
					.catch(err => {
						console.log(new Error('请检查网络后重试'));
					});
		},
		methods: {
			// bindPickerChange(e) {
			// 	console.log('picker发送选择改变，携带值为', e.target.value);
			// 	this.index = e.target.value;
			// 	this.bankCode = this.array[this.index];
			// },
			back() {
				uni.navigateTo({
					url: '../index'
				})
			},
			go_withdraw() {
				var pwd = '';
				if (this.password && this.twopwd && (this.password != this.twopwd)) {
					uni.showToast({
						title: '两次输入密码要一致哦~',
						icon: 'none'
					})
					return;
				}
				
				
				uni.showLoading({
					title: '数据加载中',
					mask: true
				});
				if (this.initData.whether.value == 1) {
					pwd = this.tixianpwd;
					if (this.bankBranch === '' || this.bankCard === '' || this.agentName === '' || this.tixianpwd === '') {
							
						uni.showToast({
							title: '您有未填的信息哦~',
							icon: 'none'
						})
						return;
					}
				} else {
					pwd = this.twopwd;
					if (this.bankBranch === '' || this.bankCard === '' || this.agentName === '' || this.twopwd === ''||this.password==='') {
							
						uni.showToast({
							title: '您有未填的信息哦~',
							icon: 'none'
						})
						return;
					}
				}
				console.log(this.array,this.array.indexOf(this.bankCode),this.bankCode)
				if(this.array.length>0&&this.array.indexOf(this.bankCode)==-1){
					uni.showToast({
						title: '开户银行只能是农业、工商、中国、建设银行哦~',
						icon: 'none'
					})
					return;
				}
				
				var params = {
					bankBranch: this.bankBranch,
					bankCard: this.bankCard,
					bankCode: this.bankCode,
					cardholder: this.agentName,
					currentTime: this.date,
					pwd: pwd,
					whether: this.whether
				}
				withdraw.apply(params)
					.then(res => {
						uni.hideLoading();
						if(res.code==200){
							uni.navigateTo({
								url:'./withdrawok?money='+this.initData.withdrawAbleAmount
							})
						}else{
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
						
					})
					.catch(err => {
						console.log(new Error('请检查网络后重试'));
					})

			}
		}
	};
</script>

<style lang="less" scoped>
	page {
		background: #ffffff;
		padding-bottom: 40rpx;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.uni-input {
		display: flex;
		justify-content: space-between;
		font-size: 30rpx;
	}

	.withdraw {
		.top {
			padding-top: ;

			.nav {
				position: relative;
				height: 44px;
				line-height: 44px;
				width: 100%;
				image{
					width: 20rpx;
					height: 36rpx;
					position: absolute;
					top: 13px;
					left: 19px;
				}
				text {
					left: 20px;
					top: 0;
					position: absolute;
				}
			}

			.flex {
				display: flex;
				flex-direction: row;
				padding: 100rpx 0 146rpx;
			}

			color: #ffffff;
			text-align: center;

			background: linear-gradient(90deg, #ff084e, #fa5d7e);

			.money {
				width: 50%;

				.number {
					font-size: 46rpx;
				}

				.text {
					margin-top: 31rpx;
					font-size: 26rpx;
				}
			}
		}

		.msg {
			padding: 0 20rpx;

			.row {
				display: flex;
				flex-direction: row;
				line-height: 84rpx;
				padding: 20rpx 0;

				picker,
				input {
					width: 100%;
					height: 84rpx;
					padding: 0 20rpx;
					box-sizing: border-box;
					border: 1px solid #e1e1e1;
					border-radius: 10rpx;
				}

				.must {
					color: #f70225;
					margin-right: 10rpx;
				}

				.text {
					width: 270rpx;

					font-size: 28rpx;
				}

				.disabled {
					width: 100%;
				}
			}
		}

		.button {
			height: 90rpx;
			line-height: 90rpx;
			margin: 50rpx 20rpx 0;
			text-align: center;
			color: #ffffff;
			border-radius: 50px;
			font-size: 32rpx;
			background: linear-gradient(90deg, #ff084e, #fa5d7e);
		}
	}
</style>
